package com.oracle.lingshangejia.activity;

import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.oracle.lingshangejia.Constant;
import com.oracle.lingshangejia.R;
import com.oracle.lingshangejia.bean.SpecialistRecordBean;
import com.oracle.lingshangejia.mvp.base.BaseActivity;
import com.oracle.lingshangejia.utils.MyToast;
import com.oracle.lingshangejia.utils.OkHttpUtils;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;

//专家查看接诊详情
public class ConsultationRecordDetailActivity extends BaseActivity {


    @BindView(R.id.tv_doctor)
    TextView mTvDoctor;
    @BindView(R.id.tv_date)
    TextView mTvDate;
    @BindView(R.id.tv_patient)
    TextView mTvPatient;
    @BindView(R.id.et_symptom)
    EditText mEtSymptom;
    @BindView(R.id.et_result)
    EditText mEtResult;
    @BindView(R.id.btn)
    Button mButton;




    @Override
    public int setLayoutId() {
        return R.layout.activity_consultation_detail;
    }


    @Override
    public void initData() {
        super.initData();
        ButterKnife.bind(this);
        mButton.setVisibility(View.GONE);
        if (getIntent() != null){
            showLoading();
            int id = getIntent().getIntExtra("id", 0);
             getNetWork(id);
             }

    }

    private void getNetWork(int jzid) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("jzid",jzid);
        OkHttpUtils.getNetWork(this, Constant.baseurl+"online/jzzz/zjHzjlDetail",map,handler);
    }
    private Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case 1:  //成功S
                    String s= (String) msg.obj;
                    Gson gson=new Gson();
                    SpecialistRecordBean bean = gson.fromJson(s,SpecialistRecordBean.class );

                    if (bean.getCode() == 0){
                        mTvDoctor.setText("医生："+bean.getData().getName());
                        mTvDate.setText("日期："+bean.getData().getHzrq());
                        mTvPatient.setText(bean.getData().getJmName());
                        mEtResult.setText(bean.getData().getHzyz());
                        mEtSymptom.setText(bean.getData().getHzyx() );
                        mEtSymptom.setEnabled(false);
                        mEtResult.setEnabled(false);
                        dismissLoading();
                    }else {
                        MyToast.show(bean.getMsg());
                    }
                 //   mBean = gson.fromJson(s, RecordTakingBean.class);
                  /*  if(mBean.getCode()==0){
                        mTvPatient.setText(mBean.getData().getJzzkgzl());

                        mTvDoctor.setText("医生："+ mBean.getData().getZzysName());
                        mTvDate.setText("日期："+mBean.getData().getJzrq().substring(0,11 ));
                    }else{
                        Toast.makeText(ConsultationRecordDetailActivity.this, mBean.getMsg(),Toast.LENGTH_SHORT).show();
                    }*/
                    break;
                case 2: //连接上服务器，错误
                    String error= (String) msg.obj;
                    Toast.makeText(ConsultationRecordDetailActivity.this,error,Toast.LENGTH_SHORT).show();
                    break;
                case 3:  //没有网络
                    Toast.makeText(ConsultationRecordDetailActivity.this,"网络不可用",Toast.LENGTH_SHORT).show();
                    break;
                case 4: //没有连接上服务器
                    Toast.makeText(ConsultationRecordDetailActivity.this,"连接服务器失败",Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    };


}
